package com.sgb.knowledgeshare.viewmodel;

import android.util.Log;
import androidx.lifecycle.ViewModel;

import com.sgb.knowledgeshare.ShareConfig;
import com.sgb.knowledgeshare.entity.ShareUserInfoEntity;
import com.sgb.knowledgeshare.view.fragment.ShareHomeUserFragment;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import com.swgk.core.view.entity.VideoListEntity;

import java.util.HashMap;
import java.util.Map;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ShareHomeUserModel extends ViewModel {
    ShareHomeUserFragment sharehomeuserfragment;
    public void setActivity(ShareHomeUserFragment shareHomeUserFragment) {
        sharehomeuserfragment = shareHomeUserFragment;
    }

//    获取用户详情信息
    public void getUserHomePage(String userid ) {
       Map map = new HashMap();
        map.put("userNo", userid );
        ShareConfig.getInstance().getApi().getUserHomePage(map).enqueue(new ICallBack<BaseEntity<ShareUserInfoEntity>>() {
            @Override
            public void onSuccess(BaseEntity<ShareUserInfoEntity> data) {
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    sharehomeuserfragment.setUserData(data.getData());
                }else {
                    sharehomeuserfragment.setUserData(new ShareUserInfoEntity());
                }
            }
        });
    }

//  关注和取消关注接口
    public void getFens(String userid) {
        Map map = new HashMap();
        map.put("userNo",userid );
        ShareConfig.getInstance().getApi().getfens(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    sharehomeuserfragment.UpdataUserIfno();
                }
            }
        });
    }

    //获取用户视频列表信息
    public void getVideoListData(int page,String userno, String userShareType) {
        Log.e("tag用户中心列表数据",userno+" ---- " );
        Map map = new HashMap();
        map.put("pageNum", page);
        map.put("pageSize", "20");
        map.put("userNo", userno);
        map.put("type", userShareType);
        map.put("videoId", "");
        ShareConfig.getInstance().getApi().getmyVodList(map).enqueue(new ICallBack<BaseEntity<VideoListEntity>>() {
            @Override
            public void onSuccess(BaseEntity<VideoListEntity> data) {
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    sharehomeuserfragment.setVideoListData(data.getData());
                }
            }
        });
    }


}
